<div id="information">
<br /><br /><br />
<?php   
   if($_GET['moda']=="edit"){
      $sel_art = mysql_query('SELECT * FROM articles WHERE article_id= '.$_GET['id'].'');
	  $row_art = mysql_fetch_assoc($sel_art);
	  ?>
	  <form method="post" action="" class="form">
			<h3 class="form_h3">Заглавие на статията:</h3>
			<p><input type="text" value="<?php echo $row_art['article_name']; ?>" name="article" /></p>
			<h3 class="form_h3">Описание на статията:</h3>
			<p><textarea cols="20" rows="3" name="descr_article" ><?php echo $row_art['article_descr']; ?></textarea></p>
			<h3 class="form_h3">Статия:</h3>
			<p><textarea name="content" id="content" cols="50" rows="7" ><?php echo $row_art['content']; ?></textarea></p>
			<p><select name="where" >
			<?php
			$sel_wh = mysql_query('SELECT name FROM modules WHERE to_tutorial = "'.$_GET['name'].'"');
			while($row_wh = mysql_fetch_assoc($sel_wh)){
			?>
			<option value="<?php echo $row_wh['name']; ?>"><?php echo $row_wh['name']; ?></option>
			<?php
			}
			?>
			</select><br /></p>
			<p><input type="submit" name="edit" value="Редактирай статията" /></p>
		</form>
	  <?php
	  include "../php/editarticles.php";
   } else {
   $sel_art = mysql_query('SELECT * FROM articles WHERE place = "'.$_GET['module'].'" AND article_id = '.$_GET['id'].'');
   
   if(mysql_num_rows($sel_art) == 0){
      echo '<p class="error">Няма уроци към този раздел!</p>';
   } else {
   
   $sel_module = mysql_query('SELECT to_tutorial FROM modules WHERE name = "'.$_GET['module'].'"');
   $row_module = mysql_fetch_assoc($sel_module);
   
   while($row_art = mysql_fetch_assoc($sel_art)){
   ?>
	   <div class="article">
	   <p style="text-align: center; font-weight: bold; font-size: 16px;"><?php echo $row_art['article_name']; ?></p>
	   <div style="margin-left: 25px; text-indent: 10px; margin-right: 25px;"><?php echo $row_art['content']; ?></div>
	   <p style="text-align: right; margin-right: 25px;">
	   <?php
	   echo "Добавено на: ".date('d-m-Y', $row_art[date_added])." от <b>".$row_art['from_who'] . "</b></p>";
	   ?>
	   </div>
	   <br />
	   <?php
	}
	}
   }
   //Comments
   $select_comments=mysql_query('SELECT * FROM comments WHERE id_article='.$_GET['id'].' ORDER BY date_added DESC');
   if(mysql_num_rows($select_comments)>0){
	
	echo '
	<h3 style="text-align: center;">Коментари</h3>
	<hr style="position: relative; top: -10px; width: 95%;"/>
	<table border="0" style="margin-left: 25px; margin-right: 25px; background-color: #fff; border-radius: 10px;">
	';
	
	while($row_comments=mysql_fetch_assoc($select_comments)){
	   $select_avatar=mysql_query('SELECT * FROM avatars WHERE from_who="'.$row_comments['from_who'].'"');
	   $row_avatar=mysql_fetch_assoc($select_avatar);
	   
	   if(mysql_num_rows($select_avatar)!=0){
	      $img1='<img src="../user_pics/'.$row_avatar[pic_name].'" width="110" height="110" style="margin-left: 10px; box-shadow: 5px 5px 5px #000" alt="avatar"/>';
	   }
	   else $img1 = '<img src="../user_pics/default.png" width="110" height="110" style="margin-left: 10px; box-shadow: 5px 5px 5px #000" alt="avatar"/>';
	   
	   echo '<tr><td style="background-color: #ccc; width: 150px;"><span style="margin-left: 25px;">Автор: <b>'.$row_comments['from_who'].'</b></span></td><td colspan="2" style="background-color: #ccc; width: 550px;"><span style="float: right; margin-right: 5px;">Добавен на: <b>'.date('d-m-Y', $row_comments[date_added]).'</b></span></td></tr>';
	   echo '<tr><td>'.$img1.'</td>';
	   echo '<td><p style="padding-bottom: 80px;">'.$row_comments['comment'].'</p>';
	   if($_SESSION['is_logged']==true && ($row_comments['from_who']==$_SESSION['username'] || $_SESSION['username']=="admin")){
	   echo '<a href="see_articles.php?name='.$_GET['name'].'&amp;id='.$_GET['id'].'&amp;delete=delete&amp;c_id='.$row_comments['id'].'&amp;module='.$_GET['module'].'"><img src="../img/delete.png" style="float: right; width: 15px; height: 15px;" alt="delete_comment"/></a></td></tr>';
	   }
	   echo '<tr><td colspan="2"><hr style="border: 1px dashed #979AA1;"/></td></tr>';
	}
	
	echo '
	</table>
	'; 
	if($_GET['delete']=="delete"){
	$delete=mysql_query('DELETE FROM comments WHERE id_article='.$_GET['id'].' AND id='.$_GET['c_id'].'');
	echo '<meta http-equiv="refresh" content="0;url=see_articles.php?name='.$_GET['name'].'&amp;id='.$_GET['id'].'&amp;module='.$_GET['module'].'">';
	}
	}
	
	if($_SESSION['is_logged']==true){
	echo '
	<div class="form_comment">
	<form method="post" action="">
	<table border="0" id="text_area" style="border-collapse: collapse;">
	<tr><td colspan="2"><div style="margin-left: 15px; font-size: 14px;">Коментар:</div></td></tr>
	<tr><td><textarea cols="40" rows="5" id="comment_text" name="comment_text"></textarea></td>
	<td><input type="submit" value="Коментирай!" name="submit_comment" id="submit_comment" style="background-color: #fff; border-radius: 6px; -moz-border-radius: 6px;"/></td></tr>
	</table>
	</form>
	<br />
	</div>
	';
	
	if($_POST['submit_comment']=="") echo "";
	else{
	   $comment=trim(addslashes(htmlspecialchars($_POST['comment_text'])));
	   if(empty($comment) || ($comment=="")){
	   
	   echo '
	   <script type="text/javascript">
	      alert("Моля, попълнете полето!");
	   </script>
	   ';
	   
	   } else {
	      if(strlen($comment)<=2){
		  
		  echo '
		  <script type="text/javascript">
	         alert("Коментарът трябва да има по-дълга дължина!");
	      </script>
		  ';
		  
		  } else {
			 $date_added=time();
			 $from_who=$_SESSION['username'];
			 $id_article=$_GET['id'];
			 
			 $insert_comment=mysql_query('INSERT INTO comments(comment, date_added, from_who, id_article) VALUES("'.$comment.'", '.$date_added.', "'.$from_who.'", '.$id_article.')');
		     echo '<meta http-equiv="refresh" content="0;url=see_articles.php?name='.$_GET['name'].'&amp;id='.$_GET['id'].'&amp;module='.$_GET['module'].'">';
		  }
	   }
	}
	} 
?>
</div>